package com.byapp.fast.common.converter;

import com.byapp.fast.common.utils.UUIDGenerator;
import com.byapp.fast.modules.order.dto.OrderItemDTO;
import com.byapp.fast.modules.order.entity.OrderItemEntity;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

public class OrderItemDTOConverter implements ConverterFactory<OrderItemEntity, OrderItemDTO> {


    @Override
    public OrderItemEntity create(OrderItemDTO orderItemDTO) {
        String itemId = UUIDGenerator.getUUID();
        return new OrderItemEntity()
                .setItemId(itemId)
                .setBuyType(Integer.parseInt(orderItemDTO.getBuyType()))
                .setPayType(orderItemDTO.getPlayType())
                .setPlayId(orderItemDTO.getPlayId())
                .setItemMoney(orderItemDTO.getBuyMoney())
                .setIsInplay(orderItemDTO.getIsInPlay())
                .setBalanceMatchId(orderItemDTO.getMatchId())
                .setCodes(orderItemDTO.getCodes())
                .setOdds(orderItemDTO.getOdds())
                .setHandicap(orderItemDTO.getHandicap())
                .setCodeTeamName(orderItemDTO.getCodeTeamName())
                ;
    }


    public static List<OrderItemEntity> mapToTarget(List<OrderItemDTO> list) {
        return !CollectionUtils.isEmpty(list) ? list.stream()
                .map(new OrderItemDTOConverter()::create)
                .collect(Collectors.toList()) : null;
    }

}
